//
//  MyViewController.m
//  MeiShiDa
//
//  Created by zby on 15/6/30.
//  Copyright (c) 2015年 zby. All rights reserved.
//

#import "MyViewController.h"
#import <SDImageCache.h>
#import <FMDB.h>
#import <SVProgressHUD.h>
#import "DetailViewController.h"
@interface MyViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)NSMutableArray *dataSourceArr;
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)UILabel *label;
@end

@implementation MyViewController

-(NSMutableArray *)dataSourceArr{
    if (!_dataSourceArr) {
        self.dataSourceArr=[[NSMutableArray alloc]initWithCapacity:0];
    }
    return _dataSourceArr;
}
-(UITableView *)tableView{
    if (!_tableView) {
        self.tableView=[[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    }
    return _tableView;
}
-(UILabel *)label{
    if (!_label) {
        self.label =[[UILabel alloc]init];
    }
    return _label;
}


-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    self.navigationItem.title=@"关于";
    
    self.dataSourceArr=[@[@"关于应用",@"清除缓存"]mutableCopy];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell2"];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    [self.view addSubview:_tableView];
    [_tableView reloadData];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:19],NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.724 green:0.389 blue:1.000 alpha:1.000];
    self.navigationController.navigationBar.translucent=NO;
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [_dataSourceArr count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell2" forIndexPath:indexPath];
    cell.textLabel.text=_dataSourceArr[indexPath.row];
    
    
    switch (indexPath.row) {
        case 0:{
            UIImageView *image=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"iconfont-jiantou-1"]];
            cell.accessoryView=image;
        }
            break;
//        case 1:{
//            UISegmentedControl *segment=[[UISegmentedControl alloc]initWithItems:@[@"小",@"中",@"大"]];
//            cell.accessoryView=segment;
//        }
            
//            break;
//        case 1:
//        {
//            UISwitch *sth=[[UISwitch alloc]init];
//            [sth addTarget:self action:@selector(send) forControlEvents:UIControlEventValueChanged];
//            cell.accessoryView=sth;
//        }

        case 1:
        {
//            NSFileManager *mgr=[NSFileManager defaultManager];
//            NSString *path=[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
//            BOOL dir=NO;
            
            double size=[SDImageCache sharedImageCache].getSize/1000.0/1000.0;
            self.label.text=[NSString stringWithFormat:@"%.1fM",size];
            _label.frame=CGRectMake(0, 0, 50, 30);
            cell.accessoryView=_label;
        }
            break;
            
        default:
            break;
    }
    
    
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:
        {
            DetailViewController *detailVC=[[DetailViewController alloc]init];
            detailVC.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
            [self.navigationController pushViewController:detailVC animated:YES];
        }
            break;
//        case 1:
//            
//            break;
        case 1:
        {
            [SVProgressHUD showSuccessWithStatus:@"清理成功" maskType:SVProgressHUDMaskTypeBlack];
            [[SDImageCache sharedImageCache] clearDisk];
            [_tableView reloadData];
            
        }
            
            break;
        default:
            break;
    }
}





-(void)send{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
